package com.akk.module.avs.service;

import com.akk.module.avs.entity.Bank;
import com.akk.module.avs.entity.BankExample;
import com.akk.module.avs.entity.ClearBankCode;
import com.akk.module.avs.entity.ClearBankCodeExample;
import com.akk.module.avs.mapper.BankMapper;
import com.akk.module.avs.mapper.ClearBankCodeMapper;
import com.akk.utils.RestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BankService {

    @Autowired
    private BankExample bankExamplel;

    @Autowired
    private BankMapper bankMapper;

    @Autowired
    private ClearBankCodeExample clearBankCodeExample;

    @Autowired
    private ClearBankCodeMapper clearBankCodeMapper;

    public List<Bank> allBanks(){
        bankExamplel.clear();
        bankExamplel.createCriteria();
        return bankMapper.selectByExample(bankExamplel);
    }

    public List<ClearBankCode> bankCodes(){
        clearBankCodeExample.clear();
        clearBankCodeExample.createCriteria();
        return clearBankCodeMapper.selectByExample(clearBankCodeExample);
    }

    public List<ClearBankCode> bankCodeByBank(Integer bankNo){
        clearBankCodeExample.clear();
        clearBankCodeExample.createCriteria().andBankpidEqualTo(bankNo);
        return clearBankCodeMapper.selectByExample(clearBankCodeExample);
    }

    public List<ClearBankCode> searchBanks(String keys) {
        if (!keys.contains(","))
            return null;
        String[] key = keys.split(",");
        clearBankCodeExample.clear();
        ClearBankCodeExample.Criteria criteria = clearBankCodeExample.createCriteria();
        for (String key1:key) {
            criteria.andBanknameLike("%"+key1+"%");
        }
//        clearBankCodeExample.createCriteria().andBanknameLike("%"+city+"%").andBanknameLike("%"+bankName+"%");
        return clearBankCodeMapper.selectByExample(clearBankCodeExample);
    }
}
